nasgfandomcom-20200214-history
Meta System
Registation Macros These are the different macros you will use for registering data to the Meta System in the engine. This should be done at the bottom of the class in the header file to keep any issues from coming up with the different access specifiers. CLASS_START(type) This is the macro that starts the registration. It takes one parameter which is the class you are registering. This macro does a few things but it isn't very important to know. It creates two methods that you shouldn't probably use: ForceStatcLink and RegisterMetaData. ForceStatic link allows some static static data to construct since it is used somewhere, which then allows the RegisterMetaData method to be called since the static data is being constructed. The main method that you are getting out of this is the GetMeta '''method which is a virtual method that can be used in various situtations when you need to know its true type. '''CLASS_END This marks the end of the registation. DERIVE(parent) Informs the Meta System that this class has something it inherits from. Used for Lua information and when looking up members/methods in Meta System for the type. CONSTRUCTOR(...) Registers the constructor to be used within the lua scripts. The arguments for the constructor is what you pass into the macro. Only ONE constructor can be registered. If you need to overload it, you need to have a constructor that takes a lua_State *. BIND_LUA Informs the Meta System to bind to Lua. This should be at the end of the registration. BIND_LUA_DELAY(delay) Informs the Meta System to bind to Lua, but is delayed so that other classes bind before. You can put in a number that marks how delayed it will be. Higher the number, the later it will be bound to Lua. NAMESPACE(name) Used to put the class into a namespace in Lua. You can have as many namespaces as you want for the class. MEMBER(member) Registers a member to the meta system. If the member has an "m_" at the beginning, that will be removed to make it easier to use in Lua Scripts. MEMBER_NAME(name, member) Registers a member to the meta system and takes a string as the first parameter to change the name of the member. These next macros are added onto the MEMBER and MEMBER_NAME macros. If you need an example, look at the bottom of this page. SCRIPT Enables this member to be used in a script. SERIALIZE Enables this member to be serialized. METHOD(method) Takes a method to register to the Meta System. METHOD_NAME(name, method) Takes a method to register to the Meta System. This macro takes a string for a name. METHOD_OVERLOAD(type, method) Registers an overloaded method to the Meta System. You need to put the exact function signature as the first parameter so the compiler knows which method to use to register. METHOD_OVERLOAD(type, name, method) Registers an overloaded method to the Meta System but also takes a string for a name. The next macro is added onto the Method macros. If you need an example, look at the bottom of this page. SCRIPT Enables the method to be used in a script. PROPERTY('name, get, set)' Adds a property to the class to be used. The name is a string and the get method must be a const method that returns something, and the set method must take a constant reference. PROPERTY('name, get)' Adds a property to the class to be used. The name is a string and the get method must return something and be const. This will be a read only property. These two macros can be added onto the Property macros. If you need an example, look at the bottom of this page. SCRIPT Enables the Property to be used in a script. SERIALIZE Enables the Property to be serialized. Meta Macros These are the different macros that you can use in the Meta System. GET_TYPE(type) Strips away extra information to get the base type. GET_META(type) Get the meta information associated with the given type. GET_META_NAME(name) Get meta information by passing in a string. DEFINE_PRIMITIVE(type) Defines a primitive to be used in the meta system. If we need to add an extra primitive, do so in the Meta.cpp file. DEFINE_LIBRARYCLASS(type) Essentially does the same thing as DEFINE_PRIMITIVE but used to be different. Still used just incase. Documentation Macros These are the different macros that the documentation uses for generation. TAG(tag) Attaches a name to make documentation generation a little easier, like everything in the math library is tagged with "Math". CLASS_COMMENT(comment) A comment about the class that will be on the documentation. COMMENT(comment) Gives a comment to the following member, property, or method. Example This is just a quick example of how to register classes to the Meta System. Make sure MetaHeaders.h is included where needed (most likely this should be included in a precompiled header). class AnObject { public: int x; int y; private: CLASS_START(AnObject) CONSTRUCTOR(); MEMBER(x).SERIALIZE.SCRIPT; MEMBER(y).SERIALIZE.SCRIPT; BIND_LUA; CLASS_END }; class Foo { public: Foo(); Foo(float, float); bool Bar(int arg1, float arg2, int arg3); void VoidFunction(float arg1, char arg2, int arg3); float GetResult() const; void SetResult(const float &result); void OverloadedFunction(int, int); void OverloadedFunction(int); static void StaticFunction(); static int StaticFunction2(int num); Foo ReturnsSelf(); Foo operator-(const Foo &rhs); virtual Foo &operator=(const Foo &); int GetConst() const; AnObject GetProperty() const; void SetProperty(const AnObject &something); static int m_StaticVariable; static const int m_static; int meh; private: float m_result; float m_Variable; float m_AnotherVariable; std::string m_TestString; AnObject m_CustomObject; AnObject m_SomethingWithProperty; const int m_ConstVariable; CLASS_START(Foo) CLASS_COMMENT("This comment will be on the documentation page for this class!"); CONSTRUCTOR(void); COMMENT("Hey look this will be a comment for m_result!"); MEMBER(m_result).SCRIPT.SERIALIZE; MEMBER(m_Variable).SCRIPT.SERIALIZE; MEMBER(m_AnotherVariable).SCRIPT.SERIALIZE; MEMBER(m_TestString).SCRIPT.SERIALIZE; MEMBER(m_CustomObject).SCRIPT.SERIALIZE; METHOD(Bar).SCRIPT; METHOD(VoidFunction).SCRIPT; METHOD_NAME("GetDerp", GetResult).SCRIPT; METHOD_OVERLOAD(void (T::*)(int, int), OverloadedFunction); METHOD(StaticFunction).SCRIPT; METHOD(StaticFunction2); METHOD(ReturnsSelf).SCRIPT; MEMBER(m_StaticVariable).SCRIPT; METHOD(operator-).SCRIPT; MEMBER(m_ConstVariable).SCRIPT; PROPERTY("AProperty", GetProperty, SetProperty).SCRIPT.SERIALIZE; BIND_LUA; CLASS_END }; int Foo::m_StaticVariable = 0; class Test : public Foo { public: void Function(); private: CLASS_START(Test) DERIVE(Foo); CONSTRUCTOR(); MEMBER(meh).SCRIPT.SERIALIZE; METHOD(Function).SCRIPT; BIND_LUA; CLASS_END };